package com.redare.dev.smart.generator.sdk.utils;

import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * Created by yangqy on 2020/12/2.
 */
public class ScriptEngine {

    public static javax.script.ScriptEngine jse = new ScriptEngineManager().getEngineByName("JavaScript");


    public static Object eval(String expression) throws ScriptException {
        Object result = jse.eval(expression);
        return result;
    }

    public static boolean expressionValid(String expression){
        try {
            Object result = jse.eval(expression);
            return true;
        } catch (ScriptException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static void main(String[] args) throws ScriptException {
        Object eval = ScriptEngine.eval("1+2*8/2+5");
    }
}
